1 module directx.xinput;
2 /***************************************************************************
3  *                                                                          *
4  *   XInput.h -- This module defines XBOX controller APIs                   *
5  *               and constansts for the Windows platform.                   *
6  *                                                                          *
7  *   Copyright (c) Microsoft Corp. All rights reserved.                     *
8  *                                                                          *
9  ***************************************************************************/
10 
11 version(Windows):
12 version(XInput):
13 
14 import directx.win32;
15 
16 // note: 9.1.0 is reduced multi-platform(winxp-win8, +xbox?) subset of XInput
17 //      that only provides most basic stuff. For advanced functionality 
18 //      use 1.3 or 1.4.
19 //      9.1.0 has its own enum values.
20 version = XINPUT_USE_1_3;
21 
22 // Current name of the DLL shipped in the same SDK as this header.
23 // The name reflects the current version
24 version(XINPUT_USE_9_1_0)
25 {
26 	enum XINPUT_DLL_A = "xinput9_1_0.dll";
27 	enum XINPUT_DLL_W = "xinput9_1_0.dll"w;
28 }
29 else
30 {
31 	enum XINPUT_DLL_A = "xinput1_3.dll";
32 	enum XINPUT_DLL_W = "xinput1_3.dll"w;
33 }
34 
35 alias XINPUT_DLL_W XINPUT_DLL;
36 
37 //
38 // Device types available in XINPUT_CAPABILITIES
39 //
40 enum XINPUT_DEVTYPE_GAMEPAD         = 0x01;
41 
42 //
43 // Device subtypes available in XINPUT_CAPABILITIES
44 //
45 enum XINPUT_DEVSUBTYPE_GAMEPAD        = 0x01;
46 
47 
48 version(XINPUT_USE_9_1_0) 
49 {
50 }
51 else
52 {
53 	enum XINPUT_DEVSUBTYPE_WHEEL          = 0x02;
54 	enum XINPUT_DEVSUBTYPE_ARCADE_STICK   = 0x03;
55 	enum XINPUT_DEVSUBTYPE_FLIGHT_SICK    = 0x04;
56 	enum XINPUT_DEVSUBTYPE_DANCE_PAD      = 0x05;
57 	enum XINPUT_DEVSUBTYPE_GUITAR         = 0x06;
58 	enum XINPUT_DEVSUBTYPE_DRUM_KIT       = 0x08;
59 }
60 
61 
62 
63 //
64 // Flags for XINPUT_CAPABILITIES
65 //
66 enum XINPUT_CAPS_VOICE_SUPPORTED      = 0x0004;
67 
68 //
69 // Constants for gamepad buttons
70 //
71 enum XINPUT_GAMEPAD_DPAD_UP           = 0x0001;
72 enum XINPUT_GAMEPAD_DPAD_DOWN         = 0x0002;
73 enum XINPUT_GAMEPAD_DPAD_LEFT         = 0x0004;
74 enum XINPUT_GAMEPAD_DPAD_RIGHT        = 0x0008;
75 enum XINPUT_GAMEPAD_START             = 0x0010;
76 enum XINPUT_GAMEPAD_BACK              = 0x0020;
77 enum XINPUT_GAMEPAD_LEFT_THUMB        = 0x0040;
78 enum XINPUT_GAMEPAD_RIGHT_THUMB       = 0x0080;
79 enum XINPUT_GAMEPAD_LEFT_SHOULDER     = 0x0100;
80 enum XINPUT_GAMEPAD_RIGHT_SHOULDER    = 0x0200;
81 enum XINPUT_GAMEPAD_A                 = 0x1000;
82 enum XINPUT_GAMEPAD_B                 = 0x2000;
83 enum XINPUT_GAMEPAD_X                 = 0x4000;
84 enum XINPUT_GAMEPAD_Y                 = 0x8000;
85 
86 
87 //
88 // Gamepad thresholds
89 //
90 enum XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE   = 7849;
91 enum XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE  = 8689;
92 enum XINPUT_GAMEPAD_TRIGGER_THRESHOLD     = 30;
93 
94 //
95 // Flags to pass to XInputGetCapabilities
96 //
97 enum XINPUT_FLAG_GAMEPAD              = 0x00000001;
98 
99 
100 version(XINPUT_USE_9_1_0)
101 {
102 }
103 else
104 {
105 //
106 // Devices that support batteries
107 //
108 enum BATTERY_DEVTYPE_GAMEPAD          = 0x00;
109 enum BATTERY_DEVTYPE_HEADSET          = 0x01;
110 
111 //
112 // Flags for battery status level
113 //
114 enum BATTERY_TYPE_DISCONNECTED        = 0x00;    // This device is not connected
115 enum BATTERY_TYPE_WIRED               = 0x01;    // Wired device, no battery
116 enum BATTERY_TYPE_ALKALINE            = 0x02;    // Alkaline battery source
117 enum BATTERY_TYPE_NIMH                = 0x03;    // Nickel Metal Hydride battery source
118 enum BATTERY_TYPE_UNKNOWN             = 0xFF;    // Cannot determine the battery type
119 
120 // These are only valid for wireless, connected devices, with known battery types
121 // The amount of use time remaining depends on the type of device.
122 enum BATTERY_LEVEL_EMPTY              = 0x00;
123 enum BATTERY_LEVEL_LOW                = 0x01;
124 enum BATTERY_LEVEL_MEDIUM             = 0x02;
125 enum BATTERY_LEVEL_FULL               = 0x03;
126 
127 // User index definitions
128 enum XUSER_MAX_COUNT                  = 4;
129 
130 enum XUSER_INDEX_ANY                  = 0x000000FF;
131 
132 
133 //
134 // Codes returned for the gamepad keystroke
135 //
136 
137 enum VK_PAD_A                         = 0x5800;
138 enum VK_PAD_B                         = 0x5801;
139 enum VK_PAD_X                         = 0x5802;
140 enum VK_PAD_Y                         = 0x5803;
141 enum VK_PAD_RSHOULDER                 = 0x5804;
142 enum VK_PAD_LSHOULDER                 = 0x5805;
143 enum VK_PAD_LTRIGGER                  = 0x5806;
144 enum VK_PAD_RTRIGGER                  = 0x5807;
145 
146 enum VK_PAD_DPAD_UP                   = 0x5810;
147 enum VK_PAD_DPAD_DOWN                 = 0x5811;
148 enum VK_PAD_DPAD_LEFT                 = 0x5812;
149 enum VK_PAD_DPAD_RIGHT                = 0x5813;
150 enum VK_PAD_START                     = 0x5814;
151 enum VK_PAD_BACK                      = 0x5815;
152 enum VK_PAD_LTHUMB_PRESS              = 0x5816;
153 enum VK_PAD_RTHUMB_PRESS              = 0x5817;
154 
155 enum VK_PAD_LTHUMB_UP                 = 0x5820;
156 enum VK_PAD_LTHUMB_DOWN               = 0x5821;
157 enum VK_PAD_LTHUMB_RIGHT              = 0x5822;
158 enum VK_PAD_LTHUMB_LEFT               = 0x5823;
159 enum VK_PAD_LTHUMB_UPLEFT             = 0x5824;
160 enum VK_PAD_LTHUMB_UPRIGHT            = 0x5825;
161 enum VK_PAD_LTHUMB_DOWNRIGHT          = 0x5826;
162 enum VK_PAD_LTHUMB_DOWNLEFT           = 0x5827;
163 
164 enum VK_PAD_RTHUMB_UP                 = 0x5830;
165 enum VK_PAD_RTHUMB_DOWN               = 0x5831;
166 enum VK_PAD_RTHUMB_RIGHT              = 0x5832;
167 enum VK_PAD_RTHUMB_LEFT               = 0x5833;
168 enum VK_PAD_RTHUMB_UPLEFT             = 0x5834;
169 enum VK_PAD_RTHUMB_UPRIGHT            = 0x5835;
170 enum VK_PAD_RTHUMB_DOWNRIGHT          = 0x5836;
171 enum VK_PAD_RTHUMB_DOWNLEFT           = 0x5837;
172 
173 //
174 // Flags used in XINPUT_KEYSTROKE
175 //
176 enum XINPUT_KEYSTROKE_KEYDOWN         = 0x0001;
177 enum XINPUT_KEYSTROKE_KEYUP           = 0x0002;
178 enum XINPUT_KEYSTROKE_REPEAT          = 0x0004;
179 
180 }
181 
182 //
183 // Structures used by XInput APIs
184 //
185 struct _XINPUT_GAMEPAD
186 {
187     WORD                                wButtons;
188     BYTE                                bLeftTrigger;
189     BYTE                                bRightTrigger;
190     SHORT                               sThumbLX;
191     SHORT                               sThumbLY;
192     SHORT                               sThumbRX;
193     SHORT                               sThumbRY;
194 } 
195 alias _XINPUT_GAMEPAD XINPUT_GAMEPAD;
196 alias _XINPUT_GAMEPAD* PXINPUT_GAMEPAD;
197 
198 struct _XINPUT_STATE
199 {
200     DWORD                               dwPacketNumber;
201     XINPUT_GAMEPAD                      Gamepad;
202 } 
203 alias _XINPUT_STATE XINPUT_STATE;
204 alias _XINPUT_STATE* PXINPUT_STATE;
205 
206 struct _XINPUT_VIBRATION
207 {
208     WORD                                wLeftMotorSpeed;
209     WORD                                wRightMotorSpeed;
210 }
211 alias _XINPUT_VIBRATION XINPUT_VIBRATION;
212 alias _XINPUT_VIBRATION* PXINPUT_VIBRATION;
213 
214 struct _XINPUT_CAPABILITIES
215 {
216     BYTE                                Type;
217     BYTE                                SubType;
218     WORD                                Flags;
219     XINPUT_GAMEPAD                      Gamepad;
220     XINPUT_VIBRATION                    Vibration;
221 } 
222 alias _XINPUT_CAPABILITIES XINPUT_CAPABILITIES;
223 alias _XINPUT_CAPABILITIES* PXINPUT_CAPABILITIES;
224 
225 version(XINPUT_USE_9_1_0)
226 {
227 }
228 else
229 {
230 struct _XINPUT_BATTERY_INFORMATION
231 {
232     BYTE BatteryType;
233     BYTE BatteryLevel;
234 }
235 alias _XINPUT_BATTERY_INFORMATION XINPUT_BATTERY_INFORMATION;
236 alias _XINPUT_BATTERY_INFORMATION* PXINPUT_BATTERY_INFORMATION;
237 
238 struct _XINPUT_KEYSTROKE
239 {
240     WORD    VirtualKey;
241     WCHAR   Unicode;
242     WORD    Flags;
243     BYTE    UserIndex;
244     BYTE    HidCode;
245 }
246 alias _XINPUT_KEYSTROKE XINPUT_KEYSTROKE;
247 alias _XINPUT_KEYSTROKE* PXINPUT_KEYSTROKE;
248 
249 }
250 
251 //
252 // XInput APIs
253 //
254 extern (Windows) 
255 {
256 
257 DWORD XInputGetState
258 (
259     in  DWORD         dwUserIndex,  // Index of the gamer associated with the device
260     /*out*/ XINPUT_STATE* pState        // Receives the current state
261 );
262 
263 DWORD XInputSetState
264 (
265     in DWORD             dwUserIndex,  // Index of the gamer associated with the device
266     in XINPUT_VIBRATION* pVibration    // The vibration information to send to the controller
267 );
268 
269 DWORD XInputGetCapabilities
270 (
271     in  DWORD                dwUserIndex,   // Index of the gamer associated with the device
272     in  DWORD                dwFlags,       // Input flags that identify the device type
273     /*out*/ XINPUT_CAPABILITIES* pCapabilities  // Receives the capabilities
274 );
275 
276 void XInputEnable
277 (
278     in BOOL enable     // [in] Indicates whether xinput is enabled or disabled. 
279 );
280 
281 DWORD XInputGetDSoundAudioDeviceGuids
282 (
283     in  DWORD dwUserIndex,          // Index of the gamer associated with the device
284     /*out*/ GUID* pDSoundRenderGuid,    // DSound device ID for render
285     /*out*/ GUID* pDSoundCaptureGuid    // DSound device ID for capture
286 );
287 
288 version(XINPUT_USE_9_1_0)
289 {
290 }
291 else
292 {
293 
294 DWORD XInputGetBatteryInformation
295 (
296     in  DWORD                       dwUserIndex,        // Index of the gamer associated with the device
297     in  BYTE                        devType,            // Which device on this user index
298     /*out*/ XINPUT_BATTERY_INFORMATION* pBatteryInformation // Contains the level and types of batteries
299 );
300 
301 DWORD XInputGetKeystroke
302 (
303     in       DWORD dwUserIndex,              // Index of the gamer associated with the device
304              DWORD dwReserved,               // Reserved for future use
305     /*out*/  PXINPUT_KEYSTROKE pKeystroke    // Pointer to an XINPUT_KEYSTROKE structure that receives an input event.
306 );
307 
308 }
309 
310 }
311